﻿package kliment.data {
	/**
	 * ...
	 * @author	Kliment
	 * @version	1.0.6
	 * 
	 * class name: kliment.data.Time
	 */
	public class Time {
		private var _body:Number
		private var _milliseconds:Number;
		private var _seconds:Number;
		private var _minutes:Number;
		private var _hours:Number;
		private var _days:Number;
		
		public function Time(milliseconds:Number) {
			_body = milliseconds || 0;
			
			var temp:Number = _body / 1000;
			
			//_days = Math.floor(temp / (60 * 60 * 24));
			_days = Math.floor(temp / 86400);
			temp -= _days * 60 * 60 * 24;
			
			//_hours = Math.floor(temp / (60 * 60));
			_hours = Math.floor(temp / 3600);
			temp -= _hours * 60 * 60;
			
			_minutes = Math.floor(temp / 60);
			temp -= _minutes * 60;
			
			_seconds = Math.floor(temp);
			temp -= _seconds;
			
			_milliseconds = Math.floor(temp * 1000);
		}
		
		public function getMilliseconds():Number {
			return _body;
		}
		
		public function getSeconds():Number {
			return Math.floor(_body  / 1000);
		}
		
		public function getMinutes():Number {
			//return Math.floor(_body / (1000 * 60));
			return Math.floor(_body / 60000);
		}
		
		public function getHours():Number {
			//return Math.floor(_body / (1000 * 60 * 60));
			return Math.floor(_body / 3600000);
		}
		
		public function getDays():Number {
			//return Math.floor(_body / (1000 * 60 * 60 * 24));
			return Math.floor(_body / 86400000);
		}
		
		public function get milliseconds():Number { return _milliseconds; }
		/*public function set milliseconds(value:Number):Void {
			_milliseconds = value;
		}*/
		
		public function get seconds():Number { return _seconds; }
		/*public function set seconds(value:Number):Void {
			_seconds = value;
		}*/
		
		public function get minutes():Number { return _minutes; }
		/*public function set minutes(value:Number):Void {
			_minutes = value;
		}*/
		
		public function get hours():Number { return _hours; }
		/*public function set hours(value:Number):Void {
			_hours = value;
		}*/
		
		public function get days():Number { return _days; }
		/*public function set days(value:Number):Void {
			_days = value;
		}*/
		
		public function toString(delimer:String = ':'):String {
			var result:Array = new Array();
			if (_days > 0) result.push(days);
			if (_hours > 0) result.push(hours);
			if (_minutes > 0) result.push(minutes);
			if (_seconds > 0) result.push(seconds);
			if (_milliseconds > 0) result.push(milliseconds);
			return result.join(delimer);
		}
		
	}

}